package yxy.apple.http.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import yxy.apple.http.HTTPException;

public class JSONResponse extends HTTPResponse<JSONObject> {

	@Override
	protected String bodyToString(JSONObject body) {
		if (body != null) {
			return JSON.toJSONString(body);
		} else {
			return null;
		}
	}

	@Override
	protected JSONObject decodeBody(byte[] body) throws HTTPException {
		try {
			JSONObject json = (JSONObject) JSON.parse(body);
			return json;
		} catch (Exception e) {
			throw new HTTPException(e);
		}
	}

}
